package com.zimug.courses.security.basic.dao;

import com.zimug.courses.security.basic.auth.model.MyUserDetails;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: liull
 * @Description:
 * @Date: Created in 14:59 2020/11/22
 * @Modified By:
 */
public interface MyUserDetailsMapper {

    /**
     * 根据用户名查询用户信息
     */
    @Select("SELECT username,pwd,enabled FROM `user` WHERE `user`.username = #{username}")
    MyUserDetails findUserDetailsByName(String username);

    /**
     * 根据用户名查询角色code列表
     */
    @Select("SELECT role.role_code FROM role\n"
            + "LEFT JOIN user_ref_role AS urr ON role.id = urr.role_id\n"
            + "LEFT JOIN `user` ON `user`.id = urr.user_id \n"
            + "WHERE\n"
            + "`user`.username = #{username}")
    List<String> queryRolesByUsername(String username);

    List<String> queryAuthoritiesByRoleCode(@Param("roleCodes") List<String> roleCodes);
}
